var cph = '', openid = '', streetNo = '', gateNo = '';
$(function() {
	openid = $('#openid').val();
	streetNo = $('#streetNo').val();
	gateNo = $('#gateNo').val();
	if (openid != null && openid != '') {
		localStorage.setItem("openid", openid);
	} else {
		openid = localStorage.getItem("openid");
	}
	if (openid == '' || openid == null) {
		layer.open({
			content: '请关闭页面，重新扫码!'
			, skin: 'msg'
			, time: 2 //2秒后自动关闭
		});
		$('#data1').html('尊敬的车主:');
		$('#data').html('发生了点小意外');
		$('#data2').html('请关闭页面，重新扫码!');
	} else {
		localStorage.setItem("openid", openid);
		$.ajax({
			url: '/park/data/getUserInfo?openid=' + openid,
			type: 'post',
			dataType: 'json',
			success: function(res) {
				if (res.code == '200') {
					if (res.data != null && res.data.noPlateType != null && res.data.noPlateType == '1') {
						$.ajax({
							url: '/park/data/help/noPlateCphOut',
							data: 'openid=' + openid + '&streetNo=' + streetNo + '&carLicense=' + res.data.cph + '&gateNo=' + gateNo,
							dataType: 'json',
							type: 'post',
							success: function(res) {
								$('#data1').html('您的临时车牌车辆：');
								$('#data').html(res.data.cph);
								$('#data2').html('正在离场核对中..');
								location.href = '/park/redirect';
							}
						})
					} else {
						$.ajax({
							url: '/park/data/help/getNoPlateCph',
							data: 'openid=' + openid + '&streetNo=' + streetNo + '&gateNo=' + gateNo,
							dataType: 'json',
							type: 'post',
							success: function(res) {
								$('#data1').html('为您生成临时车牌：');
								$('#data').html(res.data.cph);
								$('#data2').html('车辆正在进场，抬杆中...');
							}
						})
					}
				} else {
					layer.open({
						content: '请关闭页面，重新扫码!'
						, skin: 'msg'
						, time: 2 //2秒后自动关闭
					});
				}
			}
		})
	}
})

function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}
